#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>   //exit()的头文件
#include <string.h>   //memset的头文件

int main(void){
    int fd;
    int ret;
    int buffer[1024];
    fd = open("./empty",O_WRONLY|O_CREAT|O_EXCL,
    S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
    if (fd == -1){
        perror("OPEN FILE ERROR");
        _exit(-1);
    }
    else printf("文件创建成功!\n");
    ret = lseek(fd,4096,SEEK_SET);
    if(ret == -1){
        perror("LSEEK ERROR");
        goto err;
    }

    /*初始化buffer为0xFF*/
    memset(buffer,0xFF,sizeof(buffer));

    for(int i=0;i<4;i++){
    ret = write(fd,buffer,sizeof(buffer));
    if(ret == -1){
        perror("WRITE ERROR");
        goto err;
    }
    }
    ret = 0;
err:
    close(fd);
    //_exit(0);//0表示正常结束，其他值表示检测到错误；
    //_Exit(0);
    exit(ret);//三者用法相同
}